package com.ues21.awt.view;
import java.awt.*;
import java.awt.event.*;
import com.ues21.awt.controller.*;
import javax.swing.*;

public class Login extends AbstractDialogo{
	private JTextField tusuario=null;
	private JPasswordField tpassword=null;
	
	public Login(JFrame owner){
		super(owner);
		this.h = 200;
		this.w = 200;
		
		JLabel lusuario = new JLabel("Usuario");
		lusuario.setBounds(20, 10, 120, 25);
		add(lusuario);
		
		tusuario = new JTextField();
		tusuario.setBounds(20, 35, 120, 20);		
		add(tusuario);
		
		JLabel lpassword = new JLabel("Password");
		lpassword.setBounds(20, 60, 120, 25);
		add(lpassword);
		
		tpassword = new JPasswordField();
		tpassword.setBounds(20, 85, 120, 20);		
		add(tpassword);
		
		JButton blogin = new JButton("Login");
		blogin.setBounds(20, 120, 100, 20);
		blogin.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				doLogin();
			}
		});
		add(blogin);
		setPosition(owner);
		
		addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent arg0){
				super.windowClosing(arg0);
				Controlador.callAction("logout", null);
			}
		});
	}
	
	private void doLogin(){
		ParametrosAccion params = new ParametrosAccion();
		params.add("principal",this.getOwner());
		params.add("login",this);
		params.add("user",tusuario.getText());
		params.add("password",tpassword.getText());
		Controlador.callAction("login", params);
	}
}
